package com.badlogic.androidgames.framework.impl;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
/**
 * @deprecated:加速计处理
 * @author frank
 * @date 2015年11月29日
 */
public class AccelerometerHandler implements SensorEventListener {

	/**SensorEventListener 传感器事件监听器**/
	
	float accelX;	//x轴
	float accelY;	//y轴
	float accelZ;	//z轴
	
	public AccelerometerHandler(Context context) {
		/**加速计管理器**/
		SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
		// TYPE_ACCELEROMETER 加速度感应检测
		if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() != 0) {
			Sensor accelerometer = manager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
			/**注册监听器 延迟时间的精度密度 SENSOR_DELAY_GAME 20ms**/
			manager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);	
		}
	}
	/**精度变化 accuracy 精度**/
	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// nothing to do here
	}
	/**传感器改变 Sensor 传感器**/
	@Override
	public void onSensorChanged(SensorEvent event) {
		accelX = event.values[0];
		accelY = event.values[1];
		accelZ = event.values[2];
	}
	
	public float getAccelX() {
		return accelX;
	}
	
	public float getAccelY() {
		return accelY;
	}
	
	public float getAccelZ() {
		return accelZ;
	}
}
